package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "用户管理")
@Slf4j
@RequestMapping("/user")
/**
 * @author     ：zhangheng
 * @date       ：Created in 2024/9/4 10:45
 * @description：用户管理
 * @modified By：
 * @version: 1.0
 */
public class UserControlle {
    @Autowired
    private UserService userService;
    @PutMapping
    @ApiOperation("用户的添加")
    public ResponseResult<UserVo> createRole(@RequestBody UserDto userDto,Integer PageNum) {
       UserVo userVo = userService.createRole(userDto);
        return ResponseResult.success(userVo);
    }
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("用户的分页查询")
    public ResponseResult <PageResponse<UserVo>> findUserVoPage(@RequestBody UserDto userDto,@PathVariable Integer pageNum,@PathVariable Integer pageSize){
        PageResponse<UserVo> pageResponse=userService.fingUserVoPage(userDto,pageNum,pageSize);
      return ResponseResult.success(pageResponse);
    }
    //用户的修改
    @PatchMapping
    @ApiOperation("用户的修改")
    public ResponseResult<Boolean> updateUser(@RequestBody UserDto userDto){
        Boolean flag=userService.updateUser(userDto);
        return ResponseResult.success(flag);

    }
    //禁用启用用户
    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation("启用禁用用户")
    public ResponseResult  isEnable(@PathVariable Long id, @PathVariable String status){
     userService.isEnable(id,status);
        return ResponseResult.success();
    }
    @PostMapping("/list")
    @ApiOperation("列表显示用户")
   public ResponseResult<List<UserVo>> userList(@RequestBody UserDto userDto){
        List<UserVo> list=userService.userList(userDto);
        return ResponseResult.success(list);
   }
//删除用户
    @DeleteMapping("/remove/{userIds")
    @ApiOperation("删除用户")
    public ResponseResult remove(@PathVariable Long userIds){
     userService.removeUser(userIds);
     return ResponseResult.success();

    }
}

